package com.example.cp.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.cp.config.HiddenProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by hemin on 2019/8/16.
 */
@Controller
@RequestMapping("/dangerous")
@Slf4j
public class DangerousWorkController {

    private String prefix = "system/dangerous";

    @Autowired
    RestTemplate restTemplate;

    @Autowired
    HiddenProperties hiddenProperties;


    @GetMapping("/index")
    public String index(@RequestParam String openId,ModelMap modelMap) {



        String fireUrl = hiddenProperties.getHeaderUrl() + "/dangerTask/fireTaskList";
        JSONArray result = restTemplate.getForObject(fireUrl, JSONArray.class);
        modelMap.put("fireTaskList", result.size());

        String highUrl = hiddenProperties.getHeaderUrl() + "/dangerTask/highTaskList";
        JSONArray highResult = restTemplate.getForObject(highUrl, JSONArray.class);
        modelMap.put("highTaskList", highResult.size());

        String confineUrl = hiddenProperties.getHeaderUrl() + "/dangerTask/confineTaskList";
        JSONArray confineResult = restTemplate.getForObject(confineUrl, JSONArray.class);
        modelMap.put("confineTaskList", confineResult.size());

        String earthUrl = hiddenProperties.getHeaderUrl() + "/dangerTask/earthTaskList";
        JSONArray earthResult = restTemplate.getForObject(earthUrl, JSONArray.class);
        modelMap.put("earthTaskList", earthResult.size());

        String hoistingUrl = hiddenProperties.getHeaderUrl() + "/dangerTask/hoistingTaskList";
        JSONArray hoistingResult = restTemplate.getForObject(hoistingUrl, JSONArray.class);
        modelMap.put("hoistingTaskList", hoistingResult.size());

        String brokeUrl = hiddenProperties.getHeaderUrl() + "/dangerTask/brokeTaskList";
        JSONArray brokeResult = restTemplate.getForObject(brokeUrl, JSONArray.class);
        modelMap.put("brokeTaskList", brokeResult.size());

        String plugUrl = hiddenProperties.getHeaderUrl() + "/dangerTask/plugTaskList";
        JSONArray plugResult = restTemplate.getForObject(plugUrl, JSONArray.class);
        modelMap.put("plugTaskList", plugResult.size());

        String eleUrl = hiddenProperties.getHeaderUrl() + "/dangerTask/eleTaskList";
        JSONArray eleResult = restTemplate.getForObject(eleUrl, JSONArray.class);
        modelMap.put("eleTaskList", eleResult.size());

        return prefix + "/task.html";
    }


    //高处作业部分----------------分割线

    /**
     * 跳转申请高处作业页面
     *
     * @return
     */
    @GetMapping("/highTaskfill/{isLeader}")
    public String highTaskfill(@PathVariable(value = "isLeader") boolean isLeader, ModelMap map) {
        map.put("isLeader", isLeader);
        return prefix + "/highTask-fill";
    }

    /**
     * 跳转我的高处作业列表页面
     *
     * @param userId 用户id
     * @param param  其他参数，筛选时用
     * @param map    回调参数
     * @return 跳转隐患列表页面，传递隐患数据
     */
    @GetMapping("/highTasklist")
    public String highTasklist(@RequestParam("userId") String userId,
                               @RequestParam(value = "param", required = false) String param,
                               ModelMap map) {
        String url = hiddenProperties.getHeaderUrl()
                + "/dangerTask/highTaskList?dataStatus={dataStatus}&userId={userId}&" + param;
        JSONArray jsonArray1 = restTemplate.getForObject(url, JSONArray.class, "1", userId);
        JSONArray jsonArray2 = restTemplate.getForObject(url, JSONArray.class, "2", userId);
        JSONArray jsonArray3 = restTemplate.getForObject(url, JSONArray.class, "3", userId);
        System.out.println(jsonArray1);
        map.put("data1", jsonArray1);//待处理
        map.put("data2", jsonArray2);//已处理
        map.put("data3", jsonArray3);//已填报
        return prefix + "/highTask-list";
    }

    /**
     * 跳转详情页，若果是未提交状态，则跳转到隐患填报页面
     *
     * @param taskId 隐患id
     * @param index  索引 0待整改 1已处理 2已填报
     * @param map    传输数据
     * @return 页面地址
     */
    @GetMapping("/highTaskdetails")
    public String highTaskdetails(@RequestParam("userId") String taskId,
                                  @RequestParam(value = "rectifyStatus", defaultValue = "0", required = false) Integer rectifyStatus,
                                  @RequestParam("index") Integer index,
                                  @RequestParam("status") String status,
                                  ModelMap map) {

        String highTask = hiddenProperties.getHeaderUrl() + "/dangerTask/highTask?id=" + taskId;
        JSONObject highTaskResult = restTemplate.getForObject(highTask, JSONObject.class);
        String logsUrl = hiddenProperties.getHeaderUrl() + "/log/list?entityId=" + taskId;
        JSONArray logsObject = restTemplate.getForObject(logsUrl, JSONArray.class);
        map.put("logs", logsObject);

        List fire1 = new ArrayList<Object>();
        fire1.add("{\"value\":\"0\",\"text\":\"起点\"}");
        fire1.add("{\"value\":\"1\",\"text\":\"上一步\"}");
        map.put("reject", fire1);

        System.out.println(highTaskResult);

        map.put("data", highTaskResult.get("data"));
        map.put("index", index);
        System.out.println(status);
        if (status != null && (status.equals("0") || status.equals("4"))) {
            return prefix + "/highTask-fill-edit";
        }
        return prefix + "/highTask-details";
    }

    /**
     * 跳部门转详情页，若果是未提交状态，则跳转到隐患填报页面
     *
     * @param entityId 隐患id
     * @param map      传输数据
     * @return 页面地址
     */
    @GetMapping("/highTaskdetailsDept")
    public String highTaskdetailsDept(@RequestParam("entityId") String entityId,
                                      ModelMap map) {
        String detailsUrl = hiddenProperties.getHeaderUrl() + "/dangerTask/highTask?id=" + entityId;
        String logsUrl = hiddenProperties.getHeaderUrl() + "/log/list?entityId=" + entityId;
        JSONObject detailsObject = restTemplate.getForObject(detailsUrl, JSONObject.class);
        JSONArray logsObject = restTemplate.getForObject(logsUrl, JSONArray.class);


        map.put("data", detailsObject.get("data"));
        map.put("logs", logsObject);
        return prefix + "/highTask-details";
    }


    /**
     * 跳转本单位动火作业列表页面
     *
     * @param userId 用户id
     * @param param  其他参数，筛选时用
     * @param map    回调参数
     * @return 跳转动火列表页面，传递动火数据
     */
    @GetMapping("/highTaskdeptList")
    public String highTaskdeptList(@RequestParam("userId") String userId,
                                   @RequestParam(value = "param", required = false) String param,
                                   ModelMap map) {
        log.info("deptId:{deptId},param:{param}", userId, param);
        JSONArray data1 = restTemplate.getForObject(hiddenProperties.getHeaderUrl() + "/dangerTask/highTaskList?dataStatus=4&userId=" + userId + "&" + param, JSONArray.class);
        JSONArray data2 = restTemplate.getForObject(hiddenProperties.getHeaderUrl() + "/dangerTask/highTaskList?dataStatus=5&userId=" + userId + "&" + param, JSONArray.class);
        map.put("data1", data1);
        map.put("data2", data2);
        return prefix + "/highTask-list-dept";
    }

    /**
     * 跳转到部门筛选页面
     */
    @GetMapping("/highTasksearchDept")
    public String highTasksearchDept() {
        return prefix + "/highTask-search-dept";
    }

    /**
     * 跳转筛选页面
     */
    @GetMapping("/highTasksearch")
    public String highTasksearch() {
        return prefix + "/highTask-search";
    }


    //动火作业部分-----------------------分割

    /**
     * 跳转申请动火作业页面
     *
     * @return
     */
    @GetMapping("/fill/{isLeader}")
    public String fill(@PathVariable(value = "isLeader") boolean isLeader, ModelMap map) {
        map.put("isLeader", isLeader);
        return prefix + "/fireTask-fill";
    }

    /**
     * 跳转我的动火作业列表页面
     *
     * @param userId 用户id
     * @param param  其他参数，筛选时用
     * @param map    回调参数
     * @return 跳转隐患列表页面，传递隐患数据
     */
    @GetMapping("/list")
    public String list(@RequestParam("userId") String userId,
                       @RequestParam(value = "param", required = false) String param,
                       ModelMap map) {
        String url = hiddenProperties.getHeaderUrl()
                + "/dangerTask/fireTaskList?dataStatus={dataStatus}&userId={userId}&" + param;
        JSONArray jsonArray1 = restTemplate.getForObject(url, JSONArray.class, "1", userId);
        JSONArray jsonArray2 = restTemplate.getForObject(url, JSONArray.class, "2", userId);
        JSONArray jsonArray3 = restTemplate.getForObject(url, JSONArray.class, "3", userId);
        System.out.println(jsonArray1);
        map.put("data1", jsonArray1);//待处理
        map.put("data2", jsonArray2);//已处理
        map.put("data3", jsonArray3);//已填报
        return prefix + "/fireTask-list";
    }

    /**
     * 跳转详情页，若果是未提交状态，则跳转到隐患填报页面
     *
     * @param taskId 隐患id
     * @param index  索引 0待整改 1已处理 2已填报
     * @param map    传输数据
     * @return 页面地址
     */
    @GetMapping("/details")
    public String details(@RequestParam("userId") String taskId,
                          @RequestParam(value = "rectifyStatus", defaultValue = "0", required = false) Integer rectifyStatus,
                          @RequestParam("index") Integer index,
                          @RequestParam("StatusName") String StatusName,
                          ModelMap map) {

        String fireTask = hiddenProperties.getHeaderUrl() + "/dangerTask/fireTask?id=" + taskId;
        JSONObject fireTaskResult = restTemplate.getForObject(fireTask, JSONObject.class);
        String logsUrl = hiddenProperties.getHeaderUrl() + "/log/list?entityId=" + taskId;
        JSONArray logsObject = restTemplate.getForObject(logsUrl, JSONArray.class);
        map.put("logs", logsObject);

        List fire1 = new ArrayList<Object>();
        fire1.add("{\"value\":\"0\",\"text\":\"起点\"}");
        fire1.add("{\"value\":\"1\",\"text\":\"上一步\"}");
        map.put("reject", fire1);

        System.out.println(fireTaskResult);

        map.put("data", fireTaskResult.get("data"));
        map.put("index", index);

        if (StatusName != null && StatusName.equals("审批未通过")) {
            return prefix + "/fireTask-fill-edit";
        }
        return prefix + "/fireTask-details";
    }

    /**
     * 跳部门转详情页，若果是未提交状态，则跳转到隐患填报页面
     *
     * @param entityId 隐患id
     * @param map      传输数据
     * @return 页面地址
     */
    @GetMapping("/detailsDept")
    public String detailsDept(@RequestParam("entityId") String entityId,
                              ModelMap map) {
        String detailsUrl = hiddenProperties.getHeaderUrl() + "/dangerTask/fireTask?id=" + entityId;
        String logsUrl = hiddenProperties.getHeaderUrl() + "/log/list?entityId=" + entityId;
        JSONObject detailsObject = restTemplate.getForObject(detailsUrl, JSONObject.class);
        JSONArray logsObject = restTemplate.getForObject(logsUrl, JSONArray.class);


        map.put("data", detailsObject.get("data"));
        map.put("logs", logsObject);
        return prefix + "/fireTask-details";
    }


    /**
     * 跳转本单位动火作业列表页面
     *
     * @param userId 用户id
     * @param param  其他参数，筛选时用
     * @param map    回调参数
     * @return 跳转动火列表页面，传递动火数据
     */
    @GetMapping("/firedeptList")
    public String deptList(@RequestParam("userId") String userId,
                           @RequestParam(value = "param", required = false) String param,
                           ModelMap map) {
        log.info("deptId:{deptId},param:{param}", userId, param);
        JSONArray data1 = restTemplate.getForObject(hiddenProperties.getHeaderUrl() + "/dangerTask/fireTaskList?dataStatus=4&userId=" + userId + "&" + param, JSONArray.class);
        JSONArray data2 = restTemplate.getForObject(hiddenProperties.getHeaderUrl() + "/dangerTask/fireTaskList?dataStatus=5&userId=" + userId + "&" + param, JSONArray.class);
        map.put("data1", data1);
        map.put("data2", data2);
        return prefix + "/fireTask-list-dept";
    }

    /**
     * 跳转到部门隐患筛选页面
     */
    @GetMapping("/searchDept")
    public String searchDept() {
        return prefix + "/fireTask-search-dept";
    }

    /**
     * 跳转隐患筛选页面
     */
    @GetMapping("/search")
    public String search() {
        return prefix + "/fireTask-search";
    }


    //受限空间作业部分-----------------------分割

    /**
     * 跳转申请高处作业页面
     *
     * @return
     */
    @GetMapping("/confineTaskfill/{isLeader}")
    public String confineTaskfill(@PathVariable(value = "isLeader") boolean isLeader, ModelMap map) {
        map.put("isLeader", isLeader);
        return prefix + "/confineTask-fill";
    }

    /**
     * 跳转我的高处作业列表页面
     *
     * @param userId 用户id
     * @param param  其他参数，筛选时用
     * @param map    回调参数
     * @return 跳转隐患列表页面，传递隐患数据
     */
    @GetMapping("/confineTasklist")
    public String confineTasklist(@RequestParam("userId") String userId,
                               @RequestParam(value = "param", required = false) String param,
                               ModelMap map) {
        String url = hiddenProperties.getHeaderUrl()
                + "/dangerTask/confineTaskList?dataStatus={dataStatus}&userId={userId}&" + param;
        JSONArray jsonArray1 = restTemplate.getForObject(url, JSONArray.class, "1", userId);
        JSONArray jsonArray2 = restTemplate.getForObject(url, JSONArray.class, "2", userId);
        JSONArray jsonArray3 = restTemplate.getForObject(url, JSONArray.class, "3", userId);
        System.out.println(jsonArray1);
        map.put("data1", jsonArray1);//待处理
        map.put("data2", jsonArray2);//已处理
        map.put("data3", jsonArray3);//已填报
        return prefix + "/confineTask-list";
    }

    /**
     * 跳转详情页，若果是未提交状态，则跳转到隐患填报页面
     *
     * @param taskId 隐患id
     * @param index  索引 0待整改 1已处理 2已填报
     * @param map    传输数据
     * @return 页面地址
     */
    @GetMapping("/confineTaskdetails")
    public String confineTaskdetails(@RequestParam("userId") String taskId,
                                  @RequestParam(value = "rectifyStatus", defaultValue = "0", required = false) Integer rectifyStatus,
                                  @RequestParam("index") Integer index,
                                  @RequestParam("status") String status,
                                  ModelMap map) {

        String confineTask = hiddenProperties.getHeaderUrl() + "/dangerTask/confineTask?id=" + taskId;
        JSONObject confineTaskResult = restTemplate.getForObject(confineTask, JSONObject.class);
        String logsUrl = hiddenProperties.getHeaderUrl() + "/log/list?entityId=" + taskId;
        JSONArray logsObject = restTemplate.getForObject(logsUrl, JSONArray.class);
        map.put("logs", logsObject);

        List fire1 = new ArrayList<Object>();
        fire1.add("{\"value\":\"0\",\"text\":\"起点\"}");
        fire1.add("{\"value\":\"1\",\"text\":\"上一步\"}");
        map.put("reject", fire1);

        System.out.println(confineTaskResult);

        map.put("data", confineTaskResult.get("data"));
        map.put("index", index);
        System.out.println(status);
        if (status != null && (status.equals("0") || status.equals("4"))) {
            return prefix + "/confineTask-fill-edit";
        }
        return prefix + "/confineTask-details";
    }

    /**
     * 跳部门转详情页，若果是未提交状态，则跳转到隐患填报页面
     *
     * @param entityId 隐患id
     * @param map      传输数据
     * @return 页面地址
     */
    @GetMapping("/confineTaskdetailsDept")
    public String confineTaskdetailsDept(@RequestParam("entityId") String entityId,
                                      ModelMap map) {
        String detailsUrl = hiddenProperties.getHeaderUrl() + "/dangerTask/confineTask?id=" + entityId;
        String logsUrl = hiddenProperties.getHeaderUrl() + "/log/list?entityId=" + entityId;
        JSONObject detailsObject = restTemplate.getForObject(detailsUrl, JSONObject.class);
        JSONArray logsObject = restTemplate.getForObject(logsUrl, JSONArray.class);


        map.put("data", detailsObject.get("data"));
        map.put("logs", logsObject);
        return prefix + "/confineTask-details";
    }


    /**
     * 跳转本单位动火作业列表页面
     *
     * @param userId 用户id
     * @param param  其他参数，筛选时用
     * @param map    回调参数
     * @return 跳转动火列表页面，传递动火数据
     */
    @GetMapping("/confineTaskdeptList")
    public String confineTaskdeptList(@RequestParam("userId") String userId,
                                   @RequestParam(value = "param", required = false) String param,
                                   ModelMap map) {
        log.info("deptId:{deptId},param:{param}", userId, param);
        JSONArray data1 = restTemplate.getForObject(hiddenProperties.getHeaderUrl() + "/dangerTask/confineTaskList?dataStatus=4&userId=" + userId + "&" + param, JSONArray.class);
        JSONArray data2 = restTemplate.getForObject(hiddenProperties.getHeaderUrl() + "/dangerTask/confineTaskList?dataStatus=5&userId=" + userId + "&" + param, JSONArray.class);
        map.put("data1", data1);
        map.put("data2", data2);
        return prefix + "/confineTask-list-dept";
    }

    /**
     * 跳转到部门筛选页面
     */
    @GetMapping("/confineTasksearchDept")
    public String confineTasksearchDept() {
        return prefix + "/confineTask-search-dept";
    }

    /**
     * 跳转筛选页面
     */
    @GetMapping("/confineTasksearch")
    public String confineTasksearch() {
        return prefix + "/confineTask-search";
    }


    //吊装作业部分----------------------------------分割线


    /**
     * 跳转申请高处作业页面
     *
     * @return
     */
    @GetMapping("/hoistingTaskfill/{isLeader}")
    public String hoistingTaskfill(@PathVariable(value = "isLeader") boolean isLeader, ModelMap map) {
        map.put("isLeader", isLeader);
        return prefix + "/hoistingTask-fill";
    }

    /**
     * 跳转我的高处作业列表页面
     *
     * @param userId 用户id
     * @param param  其他参数，筛选时用
     * @param map    回调参数
     * @return 跳转隐患列表页面，传递隐患数据
     */
    @GetMapping("/hoistingTasklist")
    public String hoistingTasklist(@RequestParam("userId") String userId,
                               @RequestParam(value = "param", required = false) String param,
                               ModelMap map) {
        String url = hiddenProperties.getHeaderUrl()
                + "/dangerTask/hoistingTaskList?dataStatus={dataStatus}&userId={userId}&" + param;
        JSONArray jsonArray1 = restTemplate.getForObject(url, JSONArray.class, "1", userId);
        JSONArray jsonArray2 = restTemplate.getForObject(url, JSONArray.class, "2", userId);
        JSONArray jsonArray3 = restTemplate.getForObject(url, JSONArray.class, "3", userId);
        System.out.println(jsonArray1);
        map.put("data1", jsonArray1);//待处理
        map.put("data2", jsonArray2);//已处理
        map.put("data3", jsonArray3);//已填报
        return prefix + "/hoistingTask-list";
    }

    /**
     * 跳转详情页，若果是未提交状态，则跳转到隐患填报页面
     *
     * @param taskId 隐患id
     * @param index  索引 0待整改 1已处理 2已填报
     * @param map    传输数据
     * @return 页面地址
     */
    @GetMapping("/hoistingTaskdetails")
    public String hoistingTaskdetails(@RequestParam("userId") String taskId,
                                  @RequestParam(value = "rectifyStatus", defaultValue = "0", required = false) Integer rectifyStatus,
                                  @RequestParam("index") Integer index,
                                  @RequestParam("status") String status,
                                  ModelMap map) {

        String hoistingTask = hiddenProperties.getHeaderUrl() + "/dangerTask/hoistingTask?id=" + taskId;
        JSONObject hoistingTaskResult = restTemplate.getForObject(hoistingTask, JSONObject.class);
        String logsUrl = hiddenProperties.getHeaderUrl() + "/log/list?entityId=" + taskId;
        JSONArray logsObject = restTemplate.getForObject(logsUrl, JSONArray.class);
        map.put("logs", logsObject);

        List fire1 = new ArrayList<Object>();
        fire1.add("{\"value\":\"0\",\"text\":\"起点\"}");
        fire1.add("{\"value\":\"1\",\"text\":\"上一步\"}");
        map.put("reject", fire1);

        System.out.println(hoistingTaskResult);

        map.put("data", hoistingTaskResult.get("data"));
        map.put("index", index);
        System.out.println(status);
        if (status != null && (status.equals("0") || status.equals("4"))) {
            return prefix + "/hoistingTask-fill-edit";
        }
        return prefix + "/hoistingTask-details";
    }

    /**
     * 跳部门转详情页，若果是未提交状态，则跳转到隐患填报页面
     *
     * @param entityId 隐患id
     * @param map      传输数据
     * @return 页面地址
     */
    @GetMapping("/hoistingTaskdetailsDept")
    public String hoistingTaskdetailsDept(@RequestParam("entityId") String entityId,
                                      ModelMap map) {
        String detailsUrl = hiddenProperties.getHeaderUrl() + "/dangerTask/hoistingTask?id=" + entityId;
        String logsUrl = hiddenProperties.getHeaderUrl() + "/log/list?entityId=" + entityId;
        JSONObject detailsObject = restTemplate.getForObject(detailsUrl, JSONObject.class);
        JSONArray logsObject = restTemplate.getForObject(logsUrl, JSONArray.class);


        map.put("data", detailsObject.get("data"));
        map.put("logs", logsObject);
        return prefix + "/hoistingTask-details";
    }


    /**
     * 跳转本单位动火作业列表页面
     *
     * @param userId 用户id
     * @param param  其他参数，筛选时用
     * @param map    回调参数
     * @return 跳转动火列表页面，传递动火数据
     */
    @GetMapping("/hoistingTaskdeptList")
    public String hoistingTaskdeptList(@RequestParam("userId") String userId,
                                   @RequestParam(value = "param", required = false) String param,
                                   ModelMap map) {
        log.info("deptId:{deptId},param:{param}", userId, param);
        JSONArray data1 = restTemplate.getForObject(hiddenProperties.getHeaderUrl() + "/dangerTask/hoistingTaskList?dataStatus=4&userId=" + userId + "&" + param, JSONArray.class);
        JSONArray data2 = restTemplate.getForObject(hiddenProperties.getHeaderUrl() + "/dangerTask/hoistingTaskList?dataStatus=5&userId=" + userId + "&" + param, JSONArray.class);
        map.put("data1", data1);
        map.put("data2", data2);
        return prefix + "/hoistingTask-list-dept";
    }

    /**
     * 跳转到部门筛选页面
     */
    @GetMapping("/hoistingTasksearchDept")
    public String hoistingTasksearchDept() {
        return prefix + "/hoistingTask-search-dept";
    }

    /**
     * 跳转筛选页面
     */
    @GetMapping("/hoistingTasksearch")
    public String hoistingTasksearch() {
        return prefix + "/hoistingTask-search";
    }



    //动土作业部分----------------分割线

    /**
     * 跳转申请高处作业页面
     *
     * @return
     */
    @GetMapping("/earthTaskfill/{isLeader}")
    public String earthTaskfill(@PathVariable(value = "isLeader") boolean isLeader, ModelMap map) {
        map.put("isLeader", isLeader);
        return prefix + "/earthTask-fill";
    }

    /**
     * 跳转我的高处作业列表页面
     *
     * @param userId 用户id
     * @param param  其他参数，筛选时用
     * @param map    回调参数
     * @return 跳转隐患列表页面，传递隐患数据
     */
    @GetMapping("/earthTasklist")
    public String earthTasklist(@RequestParam("userId") String userId,
                                @RequestParam(value = "param", required = false) String param,
                                ModelMap map) {
        String url = hiddenProperties.getHeaderUrl()
                + "/dangerTask/earthTaskList?dataStatus={dataStatus}&userId={userId}&" + param;
        JSONArray jsonArray1 = restTemplate.getForObject(url, JSONArray.class, "1", userId);
        JSONArray jsonArray2 = restTemplate.getForObject(url, JSONArray.class, "2", userId);
        JSONArray jsonArray3 = restTemplate.getForObject(url, JSONArray.class, "3", userId);
        System.out.println(jsonArray1);
        map.put("data1", jsonArray1);//待处理
        map.put("data2", jsonArray2);//已处理
        map.put("data3", jsonArray3);//已填报
        return prefix + "/earthTask-list";
    }

    /**
     * 跳转详情页，若果是未提交状态，则跳转到隐患填报页面
     *
     * @param taskId 隐患id
     * @param index  索引 0待整改 1已处理 2已填报
     * @param map    传输数据
     * @return 页面地址
     */
    @GetMapping("/earthTaskdetails")
    public String earthTaskdetails(@RequestParam("userId") String taskId,
                                   @RequestParam(value = "rectifyStatus", defaultValue = "0", required = false) Integer rectifyStatus,
                                   @RequestParam("index") Integer index,
                                   @RequestParam("status") String status,
                                   ModelMap map) {

        String earthTask = hiddenProperties.getHeaderUrl() + "/dangerTask/earthTask?id=" + taskId;
        JSONObject earthTaskResult = restTemplate.getForObject(earthTask, JSONObject.class);
        String logsUrl = hiddenProperties.getHeaderUrl() + "/log/list?entityId=" + taskId;
        JSONArray logsObject = restTemplate.getForObject(logsUrl, JSONArray.class);
        map.put("logs", logsObject);

        List fire1 = new ArrayList<Object>();
        fire1.add("{\"value\":\"0\",\"text\":\"起点\"}");
        fire1.add("{\"value\":\"1\",\"text\":\"上一步\"}");
        map.put("reject", fire1);

        System.out.println(earthTaskResult);

        map.put("data", earthTaskResult.get("data"));
        map.put("index", index);
        System.out.println(status);
        if (status != null && (status.equals("0") || status.equals("4"))) {
            return prefix + "/earthTask-fill-edit";
        }
        return prefix + "/earthTask-details";
    }

    /**
     * 跳部门转详情页，若果是未提交状态，则跳转到隐患填报页面
     *
     * @param entityId 隐患id
     * @param map      传输数据
     * @return 页面地址
     */
    @GetMapping("/earthTaskdetailsDept")
    public String earthTaskdetailsDept(@RequestParam("entityId") String entityId,
                                       ModelMap map) {
        String detailsUrl = hiddenProperties.getHeaderUrl() + "/dangerTask/earthTask?id=" + entityId;
        String logsUrl = hiddenProperties.getHeaderUrl() + "/log/list?entityId=" + entityId;
        JSONObject detailsObject = restTemplate.getForObject(detailsUrl, JSONObject.class);
        JSONArray logsObject = restTemplate.getForObject(logsUrl, JSONArray.class);


        map.put("data", detailsObject.get("data"));
        map.put("logs", logsObject);
        return prefix + "/earthTask-details";
    }


    /**
     * 跳转本单位动火作业列表页面
     *
     * @param userId 用户id
     * @param param  其他参数，筛选时用
     * @param map    回调参数
     * @return 跳转动火列表页面，传递动火数据
     */
    @GetMapping("/earthTaskdeptList")
    public String earthTaskdeptList(@RequestParam("userId") String userId,
                                    @RequestParam(value = "param", required = false) String param,
                                    ModelMap map) {
        log.info("deptId:{deptId},param:{param}", userId, param);
        JSONArray data1 = restTemplate.getForObject(hiddenProperties.getHeaderUrl() + "/dangerTask/earthTaskList?dataStatus=4&userId=" + userId + "&" + param, JSONArray.class);
        JSONArray data2 = restTemplate.getForObject(hiddenProperties.getHeaderUrl() + "/dangerTask/earthTaskList?dataStatus=5&userId=" + userId + "&" + param, JSONArray.class);
        map.put("data1", data1);
        map.put("data2", data2);
        return prefix + "/earthTask-list-dept";
    }

    /**
     * 跳转到部门筛选页面
     */
    @GetMapping("/earthTasksearchDept")
    public String earthTasksearchDept() {
        return prefix + "/earthTask-search-dept";
    }

    /**
     * 跳转筛选页面
     */
    @GetMapping("/earthTasksearch")
    public String earthTasksearch() {
        return prefix + "/earthTask-search";
    }





    //断路作业部分----------------分割线

    /**
     * 跳转申请高处作业页面
     *
     * @return
     */
    @GetMapping("/brokeTaskfill/{isLeader}")
    public String brokeTaskfill(@PathVariable(value = "isLeader") boolean isLeader, ModelMap map) {
        map.put("isLeader", isLeader);
        return prefix + "/brokeTask-fill";
    }

    /**
     * 跳转我的高处作业列表页面
     *
     * @param userId 用户id
     * @param param  其他参数，筛选时用
     * @param map    回调参数
     * @return 跳转隐患列表页面，传递隐患数据
     */
    @GetMapping("/brokeTasklist")
    public String brokeTasklist(@RequestParam("userId") String userId,
                                @RequestParam(value = "param", required = false) String param,
                                ModelMap map) {
        String url = hiddenProperties.getHeaderUrl()
                + "/dangerTask/brokeTaskList?dataStatus={dataStatus}&userId={userId}&" + param;
        JSONArray jsonArray1 = restTemplate.getForObject(url, JSONArray.class, "1", userId);
        JSONArray jsonArray2 = restTemplate.getForObject(url, JSONArray.class, "2", userId);
        JSONArray jsonArray3 = restTemplate.getForObject(url, JSONArray.class, "3", userId);
        System.out.println(jsonArray1);
        map.put("data1", jsonArray1);//待处理
        map.put("data2", jsonArray2);//已处理
        map.put("data3", jsonArray3);//已填报
        return prefix + "/brokeTask-list";
    }

    /**
     * 跳转详情页，若果是未提交状态，则跳转到隐患填报页面
     *
     * @param taskId 隐患id
     * @param index  索引 0待整改 1已处理 2已填报
     * @param map    传输数据
     * @return 页面地址
     */
    @GetMapping("/brokeTaskdetails")
    public String brokeTaskdetails(@RequestParam("userId") String taskId,
                                   @RequestParam(value = "rectifyStatus", defaultValue = "0", required = false) Integer rectifyStatus,
                                   @RequestParam("index") Integer index,
                                   @RequestParam("status") String status,
                                   ModelMap map) {

        String brokeTask = hiddenProperties.getHeaderUrl() + "/dangerTask/brokeTask?id=" + taskId;
        JSONObject brokeTaskResult = restTemplate.getForObject(brokeTask, JSONObject.class);
        String logsUrl = hiddenProperties.getHeaderUrl() + "/log/list?entityId=" + taskId;
        JSONArray logsObject = restTemplate.getForObject(logsUrl, JSONArray.class);
        map.put("logs", logsObject);

        List fire1 = new ArrayList<Object>();
        fire1.add("{\"value\":\"0\",\"text\":\"起点\"}");
        fire1.add("{\"value\":\"1\",\"text\":\"上一步\"}");
        map.put("reject", fire1);

        System.out.println(brokeTaskResult);

        map.put("data", brokeTaskResult.get("data"));
        map.put("index", index);
        System.out.println(status);
        if (status != null && (status.equals("0") || status.equals("3"))) {
            return prefix + "/brokeTask-fill-edit";
        }
        return prefix + "/brokeTask-details";
    }

    /**
     * 跳部门转详情页，若果是未提交状态，则跳转到隐患填报页面
     *
     * @param entityId 隐患id
     * @param map      传输数据
     * @return 页面地址
     */
    @GetMapping("/brokeTaskdetailsDept")
    public String brokeTaskdetailsDept(@RequestParam("entityId") String entityId,
                                       ModelMap map) {
        String detailsUrl = hiddenProperties.getHeaderUrl() + "/dangerTask/brokeTask?id=" + entityId;
        String logsUrl = hiddenProperties.getHeaderUrl() + "/log/list?entityId=" + entityId;
        JSONObject detailsObject = restTemplate.getForObject(detailsUrl, JSONObject.class);
        JSONArray logsObject = restTemplate.getForObject(logsUrl, JSONArray.class);


        map.put("data", detailsObject.get("data"));
        map.put("logs", logsObject);
        return prefix + "/brokeTask-details";
    }


    /**
     * 跳转本单位动火作业列表页面
     *
     * @param userId 用户id
     * @param param  其他参数，筛选时用
     * @param map    回调参数
     * @return 跳转动火列表页面，传递动火数据
     */
    @GetMapping("/brokeTaskdeptList")
    public String brokeTaskdeptList(@RequestParam("userId") String userId,
                                    @RequestParam(value = "param", required = false) String param,
                                    ModelMap map) {
        log.info("deptId:{deptId},param:{param}", userId, param);
        JSONArray data1 = restTemplate.getForObject(hiddenProperties.getHeaderUrl() + "/dangerTask/brokeTaskList?dataStatus=4&userId=" + userId + "&" + param, JSONArray.class);
        JSONArray data2 = restTemplate.getForObject(hiddenProperties.getHeaderUrl() + "/dangerTask/brokeTaskList?dataStatus=5&userId=" + userId + "&" + param, JSONArray.class);
        map.put("data1", data1);
        map.put("data2", data2);
        return prefix + "/brokeTask-list-dept";
    }

    /**
     * 跳转到部门筛选页面
     */
    @GetMapping("/brokeTasksearchDept")
    public String brokeTasksearchDept() {
        return prefix + "/brokeTask-search-dept";
    }

    /**
     * 跳转筛选页面
     */
    @GetMapping("/brokeTasksearch")
    public String brokeTasksearch() {
        return prefix + "/brokeTask-search";
    }


    //断路作业部分----------------分割线

    /**
     * 跳转申请抽堵盲板作业页面
     *
     * @return
     */
    @GetMapping("/plugTaskfill/{isLeader}")
    public String plugTaskfill(@PathVariable(value = "isLeader") boolean isLeader, ModelMap map) {
        map.put("isLeader", isLeader);
        return prefix + "/plugTask-fill";
    }

    /**
     * 跳转我的高处作业列表页面
     *
     * @param userId 用户id
     * @param param  其他参数，筛选时用
     * @param map    回调参数
     * @return 跳转隐患列表页面，传递隐患数据
     */
    @GetMapping("/plugTasklist")
    public String plugTasklist(@RequestParam("userId") String userId,
                                @RequestParam(value = "param", required = false) String param,
                                ModelMap map) {
        String url = hiddenProperties.getHeaderUrl()
                + "/dangerTask/plugTaskList?dataStatus={dataStatus}&userId={userId}&" + param;
        JSONArray jsonArray1 = restTemplate.getForObject(url, JSONArray.class, "1", userId);
        JSONArray jsonArray2 = restTemplate.getForObject(url, JSONArray.class, "2", userId);
        JSONArray jsonArray3 = restTemplate.getForObject(url, JSONArray.class, "3", userId);
        System.out.println(jsonArray1);
        map.put("data1", jsonArray1);//待处理
        map.put("data2", jsonArray2);//已处理
        map.put("data3", jsonArray3);//已填报
        return prefix + "/plugTask-list";
    }

    /**
     * 跳转详情页，若果是未提交状态，则跳转到隐患填报页面
     *
     * @param taskId 隐患id
     * @param index  索引 0待整改 1已处理 2已填报
     * @param map    传输数据
     * @return 页面地址
     */
    @GetMapping("/plugTaskdetails")
    public String plugTaskdetails(@RequestParam("userId") String taskId,
                                   @RequestParam(value = "rectifyStatus", defaultValue = "0", required = false) Integer rectifyStatus,
                                   @RequestParam("index") Integer index,
                                   @RequestParam("status") String status,
                                   ModelMap map) {

        String plugTask = hiddenProperties.getHeaderUrl() + "/dangerTask/plugTask?id=" + taskId;
        JSONObject plugTaskResult = restTemplate.getForObject(plugTask, JSONObject.class);
        String logsUrl = hiddenProperties.getHeaderUrl() + "/log/list?entityId=" + taskId;
        JSONArray logsObject = restTemplate.getForObject(logsUrl, JSONArray.class);
        map.put("logs", logsObject);

        List fire1 = new ArrayList<Object>();
        fire1.add("{\"value\":\"0\",\"text\":\"起点\"}");
        fire1.add("{\"value\":\"1\",\"text\":\"上一步\"}");
        map.put("reject", fire1);

        System.out.println(plugTaskResult);

        map.put("data", plugTaskResult.get("data"));
        map.put("index", index);
        System.out.println(status);
        if (status != null && (status.equals("0") || status.equals("4"))) {
            return prefix + "/plugTask-fill-edit";
        }
        return prefix + "/plugTask-details";
    }

    /**
     * 跳部门转详情页，若果是未提交状态，则跳转到隐患填报页面
     *
     * @param entityId 隐患id
     * @param map      传输数据
     * @return 页面地址
     */
    @GetMapping("/plugTaskdetailsDept")
    public String plugTaskdetailsDept(@RequestParam("entityId") String entityId,
                                       ModelMap map) {
        String detailsUrl = hiddenProperties.getHeaderUrl() + "/dangerTask/plugTask?id=" + entityId;
        String logsUrl = hiddenProperties.getHeaderUrl() + "/log/list?entityId=" + entityId;
        JSONObject detailsObject = restTemplate.getForObject(detailsUrl, JSONObject.class);
        JSONArray logsObject = restTemplate.getForObject(logsUrl, JSONArray.class);


        map.put("data", detailsObject.get("data"));
        map.put("logs", logsObject);
        return prefix + "/plugTask-details";
    }


    /**
     * 跳转本单位动火作业列表页面
     *
     * @param userId 用户id
     * @param param  其他参数，筛选时用
     * @param map    回调参数
     * @return 跳转动火列表页面，传递动火数据
     */
    @GetMapping("/plugTaskdeptList")
    public String plugTaskdeptList(@RequestParam("userId") String userId,
                                    @RequestParam(value = "param", required = false) String param,
                                    ModelMap map) {
        log.info("deptId:{deptId},param:{param}", userId, param);
        JSONArray data1 = restTemplate.getForObject(hiddenProperties.getHeaderUrl() + "/dangerTask/plugTaskList?dataStatus=4&userId=" + userId + "&" + param, JSONArray.class);
        JSONArray data2 = restTemplate.getForObject(hiddenProperties.getHeaderUrl() + "/dangerTask/plugTaskList?dataStatus=5&userId=" + userId + "&" + param, JSONArray.class);
        map.put("data1", data1);
        map.put("data2", data2);
        return prefix + "/plugTask-list-dept";
    }

    /**
     * 跳转到部门筛选页面
     */
    @GetMapping("/plugTasksearchDept")
    public String plugTasksearchDept() {
        return prefix + "/plugTask-search-dept";
    }

    /**
     * 跳转筛选页面
     */
    @GetMapping("/plugTasksearch")
    public String plugTasksearch() {
        return prefix + "/plugTask-search";
    }



    //临时用电作业部分----------------分割线

    /**
     * 跳转申请抽堵盲板作业页面
     *
     * @return
     */
    @GetMapping("/eleTaskfill/{isLeader}")
    public String eleTaskfill(@PathVariable(value = "isLeader") boolean isLeader, ModelMap map) {
        map.put("isLeader", isLeader);
        return prefix + "/eleTask-fill";
    }

    /**
     * 跳转我的高处作业列表页面
     *
     * @param userId 用户id
     * @param param  其他参数，筛选时用
     * @param map    回调参数
     * @return 跳转隐患列表页面，传递隐患数据
     */
    @GetMapping("/eleTasklist")
    public String eleTasklist(@RequestParam("userId") String userId,
                               @RequestParam(value = "param", required = false) String param,
                               ModelMap map) {
        String url = hiddenProperties.getHeaderUrl()
                + "/dangerTask/eleTaskList?dataStatus={dataStatus}&userId={userId}&" + param;
        JSONArray jsonArray1 = restTemplate.getForObject(url, JSONArray.class, "1", userId);
        JSONArray jsonArray2 = restTemplate.getForObject(url, JSONArray.class, "2", userId);
        JSONArray jsonArray3 = restTemplate.getForObject(url, JSONArray.class, "3", userId);
        System.out.println(jsonArray1);
        map.put("data1", jsonArray1);//待处理
        map.put("data2", jsonArray2);//已处理
        map.put("data3", jsonArray3);//已填报
        return prefix + "/eleTask-list";
    }

    /**
     * 跳转详情页，若果是未提交状态，则跳转到隐患填报页面
     *
     * @param taskId 隐患id
     * @param index  索引 0待整改 1已处理 2已填报
     * @param map    传输数据
     * @return 页面地址
     */
    @GetMapping("/eleTaskdetails")
    public String eleTaskdetails(@RequestParam("userId") String taskId,
                                  @RequestParam(value = "rectifyStatus", defaultValue = "0", required = false) Integer rectifyStatus,
                                  @RequestParam("index") Integer index,
                                  @RequestParam("status") String status,
                                  ModelMap map) {

        String eleTask = hiddenProperties.getHeaderUrl() + "/dangerTask/eleTask?id=" + taskId;
        JSONObject eleTaskResult = restTemplate.getForObject(eleTask, JSONObject.class);
        String logsUrl = hiddenProperties.getHeaderUrl() + "/log/list?entityId=" + taskId;
        JSONArray logsObject = restTemplate.getForObject(logsUrl, JSONArray.class);
        map.put("logs", logsObject);

        List fire1 = new ArrayList<Object>();
        fire1.add("{\"value\":\"0\",\"text\":\"起点\"}");
        fire1.add("{\"value\":\"1\",\"text\":\"上一步\"}");
        map.put("reject", fire1);

        System.out.println(eleTaskResult);

        map.put("data", eleTaskResult.get("data"));
        map.put("index", index);
        System.out.println(status);
        if (status != null && (status.equals("0") || status.equals("3"))) {
            return prefix + "/eleTask-fill-edit";
        }
        return prefix + "/eleTask-details";
    }

    /**
     * 跳部门转详情页，若果是未提交状态，则跳转到隐患填报页面
     *
     * @param entityId 隐患id
     * @param map      传输数据
     * @return 页面地址
     */
    @GetMapping("/eleTaskdetailsDept")
    public String eleTaskdetailsDept(@RequestParam("entityId") String entityId,
                                      ModelMap map) {
        String detailsUrl = hiddenProperties.getHeaderUrl() + "/dangerTask/eleTask?id=" + entityId;
        String logsUrl = hiddenProperties.getHeaderUrl() + "/log/list?entityId=" + entityId;
        JSONObject detailsObject = restTemplate.getForObject(detailsUrl, JSONObject.class);
        JSONArray logsObject = restTemplate.getForObject(logsUrl, JSONArray.class);


        map.put("data", detailsObject.get("data"));
        map.put("logs", logsObject);
        return prefix + "/eleTask-details";
    }


    /**
     * 跳转本单位动火作业列表页面
     *
     * @param userId 用户id
     * @param param  其他参数，筛选时用
     * @param map    回调参数
     * @return 跳转动火列表页面，传递动火数据
     */
    @GetMapping("/eleTaskdeptList")
    public String eleTaskdeptList(@RequestParam("userId") String userId,
                                   @RequestParam(value = "param", required = false) String param,
                                   ModelMap map) {
        log.info("deptId:{deptId},param:{param}", userId, param);
        JSONArray data1 = restTemplate.getForObject(hiddenProperties.getHeaderUrl() + "/dangerTask/eleTaskList?dataStatus=4&userId=" + userId + "&" + param, JSONArray.class);
        JSONArray data2 = restTemplate.getForObject(hiddenProperties.getHeaderUrl() + "/dangerTask/eleTaskList?dataStatus=5&userId=" + userId + "&" + param, JSONArray.class);
        map.put("data1", data1);
        map.put("data2", data2);
        return prefix + "/eleTask-list-dept";
    }

    /**
     * 跳转到部门筛选页面
     */
    @GetMapping("/eleTasksearchDept")
    public String eleTasksearchDept() {
        return prefix + "/eleTask-search-dept";
    }

    /**
     * 跳转筛选页面
     */
    @GetMapping("/eleTasksearch")
    public String eleTasksearch() {
        return prefix + "/eleTask-search";
    }


}//结尾